#!/bin/sh

# Part of Zombie Navigator
# Copyright © 2015  Zombie Navigator Developers

mylog () {
	echo "[`date`] $@" >&2
}

dir="`dirname "$0"`"
dir="`cd "$dir";pwd`"
cd "$dir"

PATH="$PATH:$dir/.deps/zopfli"


# Look for RSVG
if ! which rsvg-convert >/dev/null 2>&1 ; then
	mylog "Please install rsvg-convert somewhere in PATH"
	exit 1
fi

source="branding/icon.svg"
targetSmall="src/icon~`date +%s`.png"
targetLarge="src/icon64~`date +%s`.png"

mylog "Building a small icon (48x48@2x)..."
rsvg-convert -w 96 -h 96 "$source" > "$targetSmall"

mylog "Building a large icon (64x64@2x)..."
rsvg-convert -w 128 -h 128 "$source" > "$targetLarge"

# Look for Zopfli PNG
if which zopflipng >/dev/null 2>&1 ; then
	mylog "Optimizing the small icon..."
	zopflipng --iterations=500 --splitting=3 --filters=01234mepb --lossy_8bit --lossy_transparent "$targetSmall" "$targetSmall.tmp"
	mv -f "$targetSmall.tmp" "$targetSmall"
	
	mylog "Optimizing the large icon..."
	zopflipng --iterations=500 --splitting=3 --filters=01234mepb --lossy_8bit --lossy_transparent "$targetLarge" "$targetLarge.tmp"
	mv -f "$targetLarge.tmp" "$targetLarge"
else
	mylog "zopflipng is not available in PATH..."
fi

mylog "Done?"


# vim: ts=4 noet ai

